<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

Abstract Class Action extends Template {

	Protected $var = array(); //提供一个默认的模板变量

	Public function __construct() {
		$this->var['template_url'] = J::getTemplateUrl();
	}

	Public function display($template = '') {
		if (!$template) {
			$template = strtolower(substr(get_class($this), 0, -6));
			$action = get_called_method();
			$template = $template.'/'.$action;
		}
		$this->assign('__TPL__', DOMAIN.J::getTpl());
		$this->assign('__PUBLIC__', DOMAIN.J::getTemplateUrl().'/public/');
		$this->assign('var', $this->var);
		parent::display($template);
	}

	Private function _info($type, $mess, $location, $timeout) {
		$mark = ($type == 'success') ? true : false;
		if($location == ''){
			$location = 'window.history.back();';
		}else{
			$location = 'location.href = \''.$location.'\';';
		}
		$this->assign("mark", $mark);
		$this->assign("mess", $mess);
		$this->assign("timeout", $timeout);
		$this->assign("location", $location);
		$this->display('info');
		exit();
	}

	Protected function success($mess = '操作成功', $location = '', $timeout = 2) {
		$this->_info(__FUNCTION__, $mess, $location, $timeout);
	}

	Protected function error($mess = '操作失败', $location = '', $timeout = 3) {
		$this->_info(__FUNCTION__, $mess, $location, $timeout);
	}

	Protected function tips($type, $tips, $template = '') {
		$this->var[$type] = $tips;
		$this->assign('var', $this->var);
		if ($template) echo $this->fetch($template);
	}
}